# -*- coding: utf-8 -*-
#!/usr/bin/python
from plp import *
import sys
plp_init()

filesList = ["dodatki.txt","obiekty.txt","miejsca.txt","zdarzenia.txt"]
elements ={}
noteStat = {}
note = "W teatrze jest kościół i opera i premiera"
level = 20

def readFile(fileName):
		elements[fileName]={}
		file = open(fileName)
		for line in file:
			word, weight = line.split()
			for id in plp_rec(word):
				elements[fileName][id]=int(weight)
				print(word+" ----> "+weight)
			
def scoreInit():
	for e in  elements.keys():
		noteStat[e]=0
	noteStat["total"]=0
	
def checkWord(word):
	for e in  elements.keys():
		for id1 in elements[e].keys():
			for id2 in plp_rec(word):
				if (id1 == id2):
					print("Word \"" + word+"\" is in "+e)
					noteStat[e]=max(noteStat[e],elements[e][id1])
					print("Now "+e+" = "+str(noteStat[e]))
					noteStat["total"]+=1
					print

def computeScore():
	return (noteStat["miejsca.txt"]+1)*(noteStat["zdarzenia.txt"]+1)+(noteStat["obiekty.txt"])+(noteStat["dodatki.txt"])+(noteStat["total"])
					
					
					
			
for fileName in filesList:
	readFile(fileName)

scoreInit()	
	
for word in note.split():
	checkWord(word)
	
print (computeScore())


	
	
	